package com.example.uitil;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    private
    Button btn1,btn2;
    EditText et1,et2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            btn2=(Button)findViewById(R.id.register);
            btn1 =(Button)findViewById(R.id.login);
            et1 =(EditText)findViewById(R.id.name);
            et2 =(EditText)findViewById(R.id.keyword);

            btn1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.d("minafang", "Button onclick!");
                    String name = et1.getText().toString();
                    Log.d("minafang", "edit content:" + name);
                    if (name.equalsIgnoreCase("1812212134")) {
                        Toast.makeText(MainActivity.this, "it is ok!", Toast.LENGTH_LONG).show();

                    } else {
                        Toast.makeText(MainActivity.this, "input error!", Toast.LENGTH_LONG).show();
                    }
//                    SharedPreferences sp =getSharedPreferences("activity",MODE_PRIVATE);
//                    String name=sp.getString("name",null);
//                    final String keywrod=sp.getString("keyword",null);
//                    if (TextUtils.isEmpty(name)&&! TextUtils.isEmpty(keywrod)){
//                        et1.setText(name);
//                    }
//                    btn1.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            String account=et1.getText().toString();
//                            String pwd=et2.getText().toString();
//                            if (TextUtils.isEmpty(pwd)){
//
//                            }else if (!pwd.equals(keywrod)&&!TextUtils.isEmpty(keywrod)){
//
//                            }else{
//                                SharedPreferences sp =getSharedPreferences("activity",MODE_PRIVATE);
//                                SharedPreferences.Editor editor =sp.edit();
//                                editor.putString("name","account");
//                                editor.putString("keyword","pwd");
//                                editor.commit();
//                            }
//
//                            try{
//                                FileOutputStream fos=openFileOutput("1.txt",MODE_PRIVATE);
//                                fos.write("www.1.txt.com".getBytes());
//                                fos.flush();
//                                fos.close();
//                            }catch (FileNotFoundException e){
//                                e.printStackTrace();}
//                        }
//                    });
                }
//        TextView tv =(TextView)findViewById(R.id.message);
//        File root = Environment.getExternalStorageDirectory();
//        if (root.exists()&&root.canWrite()){
//            File file =new File(root,"Demo.txt");
//            try{
//                if (file.createNewFile()){
//                    tv.setText(file.getName()+"创建成功！");
//                }else {
//                    tv.setText(file.getName()+"创建失败！");
//                }
//            }catch (IOException e){
//                e.printStackTrace();
//            }
//        }else {
//            tv.setText("SD卡不存在或者不可写");
//        }
//
//    }
//
//
                    Intent intent = new  Intent(MainActivity.this,fragment.class);

            });
    }
}